package com.yn.bsc.service.impl;

import com.yn.bsc.dao.SiteHealthyDailyRecordMapper;
import com.yn.bsc.model.SiteHealthyDailyRecord;
import com.yn.bsc.service.SiteHealthyDailyRecordService;
import com.yn.bsc.core.AbstractService;
import com.yn.bsc.vo.SiteStationsVo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by ZuoLG on 2017/10/31.
 */
@Service
@Transactional
public class SiteHealthyDailyRecordServiceImpl extends AbstractService<SiteHealthyDailyRecord> implements SiteHealthyDailyRecordService {
    @Resource
    private SiteHealthyDailyRecordMapper siteHealthyDailyRecordMapper;

    @Override
    public Map<String, String> findSiteLevel(String area, String start, String end) {
        Map<String,String> resultMap = new HashMap<>();
        List<Map<Object, Object>> mapList = siteHealthyDailyRecordMapper.getSiteLevel(area,start,end);
        if (CollectionUtils.isEmpty(mapList))
            return resultMap;

        for (Map<Object,Object> map : mapList){
            Object level = null;
            Object counts = null;
            for (Map.Entry<Object, Object> entry : map.entrySet()) {
                if ("level".equals(entry.getKey())) {
                    level = entry.getValue();
                } else if ("counts".equals(entry.getKey())) {
                    counts = entry.getValue();
                }
            }
            resultMap.put(level.toString(), counts.toString());
        }
        return resultMap;
    }
}
